//
//  FarmDataListCell.m
//  YK_BaseMediator
//
//  Created by edward on 2021/3/11.
//  Copyright © 2021 Edward. All rights reserved.
//

#import "FarmDataListCell.h"
#import "YKFarmViewModel.h"
#import <Masonry/Masonry.h>
#import <YK_ExectionModel/YKUIKitCore.h>

@interface FarmDataListCell ()

///
@property(nonatomic,strong) UILabel *timeLabel;
///
@property(nonatomic,strong) UILabel *sumDrugLabel;
///
@property(nonatomic,strong) UILabel *sumFoodLabel;

@end

@implementation FarmDataListCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI
{
    self.contentView.backgroundColor = UIColor.clearColor;
    [self.contentView addSubview:self.timeLabel];
    [self.contentView addSubview:self.sumDrugLabel];
    [self.contentView addSubview:self.sumFoodLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(10);
        make.width.mas_equalTo(self.contentView.width - 20);
        make.height.mas_equalTo(30);
    }];
    [self.sumFoodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.timeLabel.mas_left);
        make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(10);
        make.width.mas_equalTo((self.contentView.width - 20)/2);
        make.height.mas_equalTo(30);
    }];
    [self.sumDrugLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.sumFoodLabel.mas_right);
        make.top.mas_equalTo(self.sumFoodLabel.mas_top);
        make.width.height.mas_equalTo(self.sumFoodLabel);
    }];
}

- (void)configDataWithViewModel:(YKFarmViewModel *)viewModel indexPath:(NSIndexPath *)indexPath dataSource:(NSArray *)dataSource
{
    @weakify(self);
    [viewModel getFarmDataListDetail:indexPath block:^(NSString * _Nonnull date, NSString * _Nonnull sumDrug, NSString * _Nonnull sumFood, NSString * _Nonnull farmId) {
        @strongify(self);
        self.timeLabel.text = date;
        self.sumDrugLabel.text = sumDrug;
        self.sumFoodLabel.text = sumFood;
    }];
}

- (UILabel *)timeLabel
{
    if(!_timeLabel)
    {
        _timeLabel = [[UILabel alloc]init];
        if (@available(iOS 13.0, *)) {
            _timeLabel.textColor = UIColor.labelColor;
        } else {
            
            _timeLabel.textColor = UIColor.blackColor;
        }
        _timeLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightRegular];
    }
    return _timeLabel;
}

- (UILabel *)sumDrugLabel
{
    if(!_sumDrugLabel)
    {
        _sumDrugLabel = [[UILabel alloc]init];
        if (@available(iOS 13.0, *)) {
            _sumDrugLabel.textColor = UIColor.labelColor;
        } else {
            
            _sumDrugLabel.textColor = UIColor.blackColor;
        }
        _sumDrugLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightBold];
        _sumDrugLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _sumDrugLabel;
}

- (UILabel *)sumFoodLabel
{
    if(!_sumFoodLabel)
    {
        _sumFoodLabel = [[UILabel alloc]init];
        if (@available(iOS 13.0, *)) {
            _sumFoodLabel.textColor = UIColor.labelColor;
        } else {
            
            _sumFoodLabel.textColor = UIColor.blackColor;
        }
        _sumFoodLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightBold];
        _sumFoodLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _sumFoodLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
